let rs = require('readline-sync')
let words: Array<string> = ['class', 'object', 'array', 'pop', 'filter']
let random_index: number = Math.floor(Math.random() * words.length)

let select_word: string = words[random_index]
let char_arr: string[] = new Array(select_word.length)
console.log(select_word);
char_arr.fill('-')
console.log(char_arr);

let guess_times: number = 5;
while (true) {
    if (guess_times === 0) {
        break
    }
    if (!char_arr.includes('-')) {
        break
    }
    let input_char: string = rs.question('please input one char:')
    let bFind: boolean = false
    console.log(input_char);
    for (let i = 0; i < select_word.length; i++) {
        if (select_word[i] === input_char) {
            if (select_word[i] === input_char) {
                char_arr[i] = input_char
                bFind = true;
            }
        }
    }

    if (bFind === false) {
        guess_times--
    }
    console.log(char_arr)
    console.log(`you have ${guess_times} left`)
}

if (guess_times !== 0) {
    console.log(`sucess`)
}